package com.zqyl.docmanager.repository;

import com.zqyl.docmanager.entity.UploadFile;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UploadFileRepository extends JpaRepository<UploadFile, Long> {
    
    // 查找未删除的文件
    @Query("SELECT f FROM UploadFile f WHERE f.isDeleted = false ORDER BY f.updateTime DESC")
    List<UploadFile> findAllActive();
    
    // 根据文件格式查找
    @Query("SELECT f FROM UploadFile f WHERE f.isDeleted = false AND f.format = ?1 ORDER BY f.updateTime DESC")
    List<UploadFile> findByFormat(String format);
    
    // 根据文件名模糊查询
    @Query("SELECT f FROM UploadFile f WHERE f.isDeleted = false AND f.fileName LIKE %?1% ORDER BY f.updateTime DESC")
    List<UploadFile> findByFileNameContaining(String fileName);
    
    // 根据状态查询
    @Query("SELECT f FROM UploadFile f WHERE f.isDeleted = false AND f.status = ?1 ORDER BY f.updateTime DESC")
    List<UploadFile> findByStatus(String status);

    // 根据格式和文件名查询
    @Query("SELECT f FROM UploadFile f WHERE f.isDeleted = false AND f.format = ?1 AND f.fileName LIKE %?2% ORDER BY f.updateTime DESC")
    List<UploadFile> findByFormatAndFileNameContaining(String format, String fileName);

    // 获取所有不重复的文件格式
    @Query("SELECT DISTINCT f.format FROM UploadFile f WHERE f.isDeleted = false")
    List<String> findAllFormats();
} 